function [xk,fk] = linesearch(fun,x,d,g)
    c1 = 5*1.0e-4; 
    beta = 0.618;
    f0 = feval(fun, x);
    alpha = 1.0e-7; 
    xk = x + alpha*d;
    fk = feval(fun,xk);
    rh = f0 + c1*alpha*(g'*d);
    
    ls = 0; 
while(fk>rh)&&(ls<20)
    ls = ls+1; 
    alpha = alpha*beta; 
    xk = x + alpha*d;
    fk = feval(fun,xk);
    rh = f0 + c1*alpha*g'*d;
end

